package group.program.Service.impl;

import com.baidubce.qianfan.Qianfan;
import group.program.Config.NlpConfig;
import group.program.Service.DbdocumentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

@Service
public class DbdocumentServiceImpl implements DbdocumentService {

    @Autowired
    private NlpConfig config;
    @Autowired
    private PdfServiceImpl pdfService;
    @Autowired
    private DocxServiceImpl docxService;

    @Override
    public String extractInformation(MultipartFile file) {
        String fileData;
        Qianfan qianfan = new Qianfan(config.getAccessKey(), config.getSecretKey());
        if (config.getQianfan() == null) {
            config.setQianfan(qianfan);
        }
        if(file.getOriginalFilename().contains(".pdf")){
            fileData = pdfService.extractInformation(file);
        }else{
            fileData = docxService.extractInformation(file);
        }
        return fileData;
    }
}
